package test;
import pojo.Employee;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Shangji1 {
    public static void main(String[] args) {
        Class siz = Employee.class;
        String simpleName = siz.getSimpleName();
        System.out.println("类名" + simpleName);
        int modifiers = siz.getModifiers();
        System.out.print("修饰符");
        if ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC)
            System.out.println("public");
        else if ((modifiers & Modifier.PROTECTED) == Modifier.PROTECTED)
            System.out.println("protected");
        else if ((modifiers & Modifier.PRIVATE) == Modifier.PRIVATE)
            System.out.println("private");
        Constructor[] cons = siz.getDeclaredConstructors();
        System.out.println("构造方式展示");
        for (Constructor con : cons) {
            System.out.print("访问修饰符：");
            int modifier = con.getModifiers();
            if ((modifier & Modifier.PUBLIC) == Modifier.PUBLIC)
                System.out.println("public");
            else if ((modifier & Modifier.PROTECTED) == Modifier.PROTECTED)
                System.out.println("protected");
            else if ((modifier & Modifier.PRIVATE) == Modifier.PRIVATE)
                System.out.println("private");
            else
                System.out.println("default(package)");

            Class[] param = con.getParameterTypes();
            if (param.length == 0) {
                System.out.println("该构造方法没有参数");
            } else {
                System.out.print("该构造方法的参数列表为：[");
                for (int i = 0; i < param.length; i++) {
                    if (i >= 0) {
                        System.out.print(", ");
                        System.out.print(param[i].getName());
                    }
                    System.out.println("]");
                }
            }

        }
        System.out.println("属性");
        //属性

        Field[] fields = siz.getDeclaredFields();
        for (Field f : fields) {
            System.out.println(f.getName());
        }
        System.out.println("方法");

        Method[] methods = siz.getDeclaredMethods();
        for (Method m : methods) {
            System.out.println(m.getName());
        }
    }
}
